﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using MM.DBUtility;
using MM.Model;
using MM.Common;

namespace MM.LibraryAPI.ZFB
{
    public class OrderHelper
    {
        /// <summary>
        /// 返回支付宝订单信息
        /// </summary>
        /// <param name="imsimac">手机IMSI+MAC</param>
        /// <param name="netType">联网请求方式 0：计费请求；1：timer请求；</param>
        /// <param name="chargeMode">计费方式：1：支付宝:；2：神州付</param>
        /// <param name="appID">游戏的id</param>
        /// <param name="prizeID">物品id</param>
        /// <param name="gameType">游戏模式 1：经典模式 2：比赛模式 3：彩池模式</param>
        /// <param name="taskID">任务（比赛）id</param>
        /// <param name="price">金额</param>
        /// <returns></returns>
        public static List<Order> GetOrderInfo(string imsi, string mac, string imei, int chargeMode, string pid, string appID,
            decimal price, string prizeName, string param, string userAccount)
        {
            List<Order> list = new List<Order>();
            using (SqlConnection conn = new SqlConnection(DbHelperSql.connectionString))
            {
                SqlParameter[] parameters = { 
                       new SqlParameter("@imsi", SqlDbType.VarChar),
                       new SqlParameter("@mac", SqlDbType.VarChar),
                       new SqlParameter("@imei", SqlDbType.VarChar),
                       new SqlParameter("@chargeMode", SqlDbType.Int),
                       new SqlParameter("@pID", SqlDbType.VarChar),
                       new SqlParameter("@appID", SqlDbType.VarChar),
                       new SqlParameter("@price", SqlDbType.Decimal),
                       new SqlParameter("@params", SqlDbType.VarChar),
                       new SqlParameter("@prizeName", SqlDbType.NVarChar),
                       new SqlParameter("@userAccount", SqlDbType.VarChar)};
                parameters[0].Value = imsi;
                parameters[1].Value = mac;
                parameters[2].Value = imei;
                parameters[3].Value = chargeMode;
                parameters[4].Value = pid;
                parameters[5].Value = appID;
                parameters[6].Value = price;
                parameters[7].Value = param;
                parameters[8].Value = prizeName;
                parameters[9].Value = userAccount;

                using (SqlDataReader dr = DbHelperSql.ExecuteReaderSP(conn, "AddOrderZFBNew", parameters))
                {
                    if (dr != null && dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            Order model = DTOHelper.New<Order>();
                            model.LoadData(dr);
                            list.Add(model);
                        }
                    }
                    dr.Close();
                }
            }
            return list;
        }
        /// <summary>
        /// 设置订单状态为成功
        /// </summary>
        /// <param name="OrderID"></param>
        public static void SetOrderStatus(string OrderID)
        {
            string strSQL = "UPDATE T_Order SET Status=1,PayTime=getdate() WHERE OrderID=@OrderID";
            SqlParameter[] parameters = { new SqlParameter("@OrderID", OrderID.ToDecimal()) };
            DbHelperSql.ExecuteSql(strSQL, parameters);
        }
    }
}
